home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume6 / compress.xenix < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  8.8 KB

  1. Subject: v06i023:  Xenix patches to compress4.0 (compress.xenix)
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.UUCP
  4.  
  5. Submitted by: condor!genrad!panda!talcott!seismo!vrdxhq!BMS-AT!stuart
  6. Mod.sources: Volume 6, Issue 23
  7. Archive-name: compress.xenix
  8.  
  9. [  The source that was submitted had the final hunk look like this:
  10.     1380c1443
  11.     < long int num, den;    /* never want 16-bit */
  12.     ---
  13.     > count_int num, den;
  14.     1407a1471,1473
  15.     > #endif
  16.     > #ifdef XENIX_16
  17.     >     fprintf(stderr, "XENIX_16, ");
  18.    My copy, and the one in the mod.sources archive, doesn't have the
  19.    "never want" comment.
  20.  
  21.    I patched a copy of the source and compiled and ran it.  Both
  22.    the patched version and the "official" version work together,
  23.    and generate identical output from identical input.  This holds
  24.    for my 4.2BSD Vax750; no guarantees on other machines, and I
  25.    don't have Xenix.  --r$]
  26.  
  27.     I recently received the shell archives for compress and related
  28. utilities.  We are running a 16-bit Xenix machine as well as a 16/32 bit
  29. motorola 6350.  The XENIX_16 code for compress did not work.  The
  30. problem was:
  31.     a) a problem with the large model code optimizer.
  32.     b) the constant (1<<16) as assigned to maxcode evaluates
  33.        to zero on a 16 bit machine!
  34. After fixing problem b, I removed the XENIX_16 code and instead declared
  35. the large arrays as 'huge'.  This allows a small model program that uses
  36. 32-bit pointers only for codetab and htab.  This also removes the kludge
  37. code for multiple arrays.  Defining the big constants as long
  38. is not necessary on our compiler, but doesn't hurt and may help other
  39. 16-bit compilers.  I changed the logic slightly in compress() and
  40. decompress() to allow the use of unsigned short for heavily used variables
  41. containing code values.  This makes things about 5% faster on a 16-bit
  42. machine.  Please mail me some comments about whether you appreciate
  43. this mail.
  44.  
  45.     Stuart D. Gathman <vrdxhq!BMS-AT!stuart>
  46.  
  47. #!/bin/sh
  48. # This is a shell archive.  Remove anything before this line,
  49. # then unpack it by saving it in a file and typing "sh file".
  50. # Contents:  compress.patch
  51.  
  52. echo x - compress.patch
  53. sed 's/^XX//' > "compress.patch" <<'@//E*O*F compress.patch//'
  54. XX22c22
  55. XX< # define USERMEM     450000L    /* default user memory */
  56. XX---
  57. XX> # define USERMEM     450000    /* default user memory */
  58. XX46,49d45
  59. XX< #ifndef M_XENIX
  60. XX< #  define huge        /* needed only for 16-bit machines */
  61. XX< #endif
  62. XX< 
  63. XX51c47
  64. XX< # if USERMEM >= (433484L+SACREDMEM)
  65. XX---
  66. XX> # if USERMEM >= (433484+SACREDMEM)
  67. XX78c74
  68. XX< # define HSIZE    69001L        /* 95% occupancy */
  69. XX---
  70. XX> # define HSIZE    69001        /* 95% occupancy */
  71. XX81c77
  72. XX< # define HSIZE    35023L        /* 94% occupancy */
  73. XX---
  74. XX> # define HSIZE    35023        /* 94% occupancy */
  75. XX92a89,98
  76. XX> #ifdef M_XENIX            /* Stupid compiler can't handle arrays with */
  77. XX> # if BITS == 16            /* more than 65535 bytes - so we fake it */
  78. XX> #  define XENIX_16
  79. XX> # else
  80. XX> #  if BITS > 13            /* Code only handles BITS = 12, 13, or 16 */
  81. XX> #   define BITS    13
  82. XX> #  endif
  83. XX> # endif
  84. XX> #endif
  85. XX> 
  86. XX259c265
  87. XX< code_int maxmaxcode;            /* should NEVER generate this code */
  88. XX---
  89. XX> code_int maxmaxcode = 1 << BITS;    /* should NEVER generate this code */
  90. XX261c267
  91. XX< # define MAXCODE(n_bits)    ((code_int)1 << (n_bits) - 1)
  92. XX---
  93. XX> # define MAXCODE(n_bits)    (1 << (n_bits) - 1)
  94. XX263c269
  95. XX< # define MAXCODE(n_bits)    (((code_int)1 << (n_bits)) - 1)
  96. XX---
  97. XX> # define MAXCODE(n_bits)    ((1 << (n_bits)) - 1)
  98. XX266,267c272,298
  99. XX< count_int huge htab [HSIZE];
  100. XX< unsigned short huge codetab [HSIZE];
  101. XX---
  102. XX> #ifdef XENIX_16
  103. XX> count_int htab0[8192];
  104. XX> count_int htab1[8192];
  105. XX> count_int htab2[8192];
  106. XX> count_int htab3[8192];
  107. XX> count_int htab4[8192];
  108. XX> count_int htab5[8192];
  109. XX> count_int htab6[8192];
  110. XX> count_int htab7[8192];
  111. XX> count_int htab8[HSIZE-65536];
  112. XX> count_int * htab[9] = {
  113. XX>     htab0, htab1, htab2, htab3, htab4, htab5, htab6, htab7, htab8 };
  114. XX> 
  115. XX> #define htabof(i)    (htab[(i) >> 13][(i) & 0x1fff])
  116. XX> unsigned short code0tab[16384];
  117. XX> unsigned short code1tab[16384];
  118. XX> unsigned short code2tab[16384];
  119. XX> unsigned short code3tab[16384];
  120. XX> unsigned short code4tab[16384];
  121. XX> unsigned short * codetab[5] = {
  122. XX>     code0tab, code1tab, code2tab, code3tab, code4tab };
  123. XX> 
  124. XX> #define codetabof(i)    (codetab[(i) >> 14][(i) & 0x3fff])
  125. XX> 
  126. XX> #else    /* Normal machine */
  127. XX> count_int htab [HSIZE];
  128. XX> unsigned short codetab [HSIZE];
  129. XX269a301
  130. XX> #endif    /* XENIX_16 */
  131. XX283,284c315,321
  132. XX< # define tab_suffixof(i)    ((char_type huge *)(htab))[i]
  133. XX< # define de_stack        ((char_type huge *)&tab_suffixof(1<<BITS))
  134. XX---
  135. XX> #ifdef XENIX_16
  136. XX> # define tab_suffixof(i)    ((char_type *)htab[(i)>>15])[(i) & 0x7fff]
  137. XX> # define de_stack        ((char_type *)(htab2))
  138. XX> #else    /* Normal machine */
  139. XX> # define tab_suffixof(i)    ((char_type *)(htab))[i]
  140. XX> # define de_stack        ((char_type *)&tab_suffixof(1<<BITS))
  141. XX> #endif    /* XENIX_16 */
  142. XX485c522
  143. XX<     maxmaxcode = (code_int)1 << maxbits;
  144. XX---
  145. XX>     maxmaxcode = 1 << maxbits;
  146. XX513c550
  147. XX<             maxmaxcode = (code_int)1 << maxbits;
  148. XX---
  149. XX>             maxmaxcode = 1 << maxbits;
  150. XX631c668
  151. XX<         maxmaxcode = (code_int)1 << maxbits;
  152. XX---
  153. XX>         maxmaxcode = 1 << maxbits;
  154. XX675c712
  155. XX<     register code_int i = 0;    /* must hold HSIZE */
  156. XX---
  157. XX>     register code_int i = 0;
  158. XX677,678c714,719
  159. XX<     register unsigned ent;    /* must hold BITS bits */
  160. XX<     register code_int disp;    /* must hold HSIZE */
  161. XX---
  162. XX>     register code_int ent;
  163. XX> #ifdef XENIX_16
  164. XX>     register code_int disp;
  165. XX> #else    /* Normal machine */
  166. XX>     register int disp;
  167. XX> #endif
  168. XX809,810c850,851
  169. XX< output( incode )
  170. XX<   code_int  incode;
  171. XX---
  172. XX> output( code )
  173. XX> code_int  code;
  174. XX821d861
  175. XX<     register unsigned short code;
  176. XX829,830c869
  177. XX<     if ( incode >= 0 ) {
  178. XX<     code = incode;
  179. XX---
  180. XX>     if ( code >= 0 ) {
  181. XX863c902
  182. XX<     if (bits)
  183. XX---
  184. XX>     if(bits)
  185. XX938c977
  186. XX<     register char_type huge *stackp;
  187. XX---
  188. XX>     register char_type *stackp;
  189. XX940,941c979
  190. XX<     register unsigned short code;
  191. XX<     register code_int oldcode, incode;
  192. XX---
  193. XX>     register code_int code, oldcode, incode;
  194. XX947,949c985,987
  195. XX<     for ( incode = 255; incode >= 0; incode-- ) {
  196. XX<     tab_prefixof(incode) = 0;
  197. XX<     tab_suffixof(incode) = (char_type)incode;
  198. XX---
  199. XX>     for ( code = 255; code >= 0; code-- ) {
  200. XX>     tab_prefixof(code) = 0;
  201. XX>     tab_suffixof(code) = (char_type)code;
  202. XX956c994
  203. XX<     putchar( finchar );        /* first code must be 8 bits = char */
  204. XX---
  205. XX>     putchar( (char)finchar );        /* first code must be 8 bits = char */
  206. XX961c999
  207. XX<     while ( (incode = getcode()) > -1 ) {
  208. XX---
  209. XX>     while ( (code = getcode()) > -1 ) {
  210. XX963d1000
  211. XX<     code = incode;
  212. XX965,966c1002,1003
  213. XX<         for ( incode = 255; incode >= 0; incode-- )
  214. XX<         tab_prefixof(incode) = 0;
  215. XX---
  216. XX>         for ( code = 255; code >= 0; code-- )
  217. XX>         tab_prefixof(code) = 0;
  218. XX969c1006
  219. XX<         if ( (incode = getcode ()) == -1 )    /* O, untimely death! */
  220. XX---
  221. XX>         if ( (code = getcode ()) == -1 )    /* O, untimely death! */
  222. XX971d1007
  223. XX<         code = incode;
  224. XX972a1009
  225. XX>     incode = code;
  226. XX984c1021,1025
  227. XX<     while ( code >= 256 ) {        /* already unsigned compare */
  228. XX---
  229. XX> #ifdef SIGNED_COMPARE_SLOW
  230. XX>     while ( ((unsigned long)code) >= ((unsigned long)256) ) {
  231. XX> #else
  232. XX>     while ( code >= 256 ) {
  233. XX> #endif
  234. XX1000,1001c1041
  235. XX<     if ( free_ent < maxmaxcode ) {
  236. XX<         code = free_ent++;
  237. XX---
  238. XX>     if ( (code=free_ent) < maxmaxcode ) {
  239. XX1003a1044
  240. XX>         free_ent = code+1;
  241. XX1025c1066,1067
  242. XX< code_int getcode() {
  243. XX---
  244. XX> code_int
  245. XX> getcode() {
  246. XX1030c1072
  247. XX<     register unsigned short code;
  248. XX---
  249. XX>     register code_int code;
  250. XX1093c1135
  251. XX<     return (code_int)code;
  252. XX---
  253. XX>     return code;
  254. XX1185,1186c1227,1228
  255. XX<        for ( ; ent != 0;
  256. XX<            ent = (ent >= FIRST ? tab_prefixof(ent) : 0) ) {
  257. XX---
  258. XX>        for ( ; ent != NULL;
  259. XX>            ent = (ent >= FIRST ? tab_prefixof(ent) : NULL) ) {
  260. XX1350c1392,1398
  261. XX<     register count_int huge *htab_p = htab+hsize;
  262. XX---
  263. XX> #ifndef XENIX_16    /* Normal machine */
  264. XX>     register count_int *htab_p = htab+hsize;
  265. XX> #else
  266. XX>     register j;
  267. XX>     register long k = hsize;
  268. XX>     register count_int *htab_p;
  269. XX> #endif
  270. XX1353a1402,1411
  271. XX> #ifdef XENIX_16
  272. XX>     for(j=0; j<=8 && k>=0; j++,k-=8192) {
  273. XX>     i = 8192;
  274. XX>     if(k < 8192) {
  275. XX>         i = k;
  276. XX>     }
  277. XX>     htab_p = &(htab[j][i]);
  278. XX>     i -= 16;
  279. XX>     if(i > 0) {
  280. XX> #else
  281. XX1354a1413
  282. XX> #endif
  283. XX1373a1433,1436
  284. XX> #ifdef XENIX_16
  285. XX>     }
  286. XX>     }
  287. XX> #endif
  288. XX1380c1443
  289. XX< long int num, den;
  290. XX---
  291. XX> count_int num, den;
  292. XX1407a1471,1473
  293. XX> #endif
  294. XX> #ifdef XENIX_16
  295. XX>     fprintf(stderr, "XENIX_16, ");
  296. @//E*O*F compress.patch//
  297. chmod u=rw,g=rw,o=rw compress.patch
  298.  
  299. echo Inspecting for damage in transit...
  300. temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
  301. trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
  302. cat > $temp <<\!!!
  303.      242    1026    5968 compress.patch
  304. !!!
  305. wc  compress.patch | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
  306. if test -s $dtemp
  307. then echo "Ouch [diff of wc output]:" ; cat $dtemp
  308. else echo "No problems found."
  309. fi
  310. exit 0
  311.